package com.qianfeng.openapi.search.controller;

import com.qianfeng.openapi.search.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/12/30
 * @Time: 上午9:31
 */
@RestController
@RequestMapping("/search")
@Api(value = "搜索模块api",description = "search模块在线api")
public class SearchController {

    @Resource
    private SearchService searchService;


    @RequestMapping("/statAvg")
    @ApiOperation(value = "获得每个api调用平均时长",notes = "获得每个api调用平均时长")
    public Map<String, Integer> statAvg(
            @ApiParam(name = "startTime",value ="开始时间 单位毫秒",defaultValue = "10") @RequestParam("startTime") long startTime,
            @ApiParam(name = "endTime",value ="结束时间 单位毫秒",defaultValue = "9999090999999999") @RequestParam("endTime")long endTime) throws  Exception {
        return  searchService.statAvg(startTime,endTime);

    }
    @PostMapping("/count")
    @ApiOperation(value = "统计满足条件的记录数",notes = "统计满足条件的记录数")
    //{requestContent:"",startTime:10}
    public long count(
            @ApiParam(name = "params",value ="查询条件封装json")@RequestBody String params) throws IOException{
        return  searchService.count(params);
    }

    @PostMapping("/searchLog")
    @ApiOperation(value = "查询满足条件的日志信息",notes = "满足条件的日志信息")
    public List<Map> search(@ApiParam(name = "params",value ="查询条件封装json")
                                @RequestBody String params) throws IOException{
        return  searchService.search(params);
    }





}
